package com.fosu.web.controller;
import com.alibaba.fastjson.JSONObject;
import com.fosu.common.ResponseResult;
import com.fosu.service.CommentService;
import com.fosu.service.impl.CommentServiceImpl;
import com.fosu.domain.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Desription
 * 单独获得商品评论接口
 * @author manno
 * @date 2020/10/15
 */
@RestController
@CrossOrigin
@RequestMapping("comment")
public class CommentController
{
    @Autowired
    CommentService commentService;

    /**
     * 获得商品详情页下的所有热门评论(按页获取)
     */
    @GetMapping("/getProductCommentsById")
    ResponseResult getProductComments(@RequestParam int productId, @RequestParam int currpage, @RequestParam int pagesize, HttpServletResponse resp) {
        return commentService.findProductComments(resp, currpage, pagesize, productId);
    }

    /**
     * 切换评论点赞状态
     */
    @RequestMapping("/switchCommentFavorite")
    ResponseResult switchFavorite(@RequestParam Integer userId, @RequestParam Integer commentId, HttpServletResponse resp) {
        return commentService.switchWhetherToFavorite(resp, userId, commentId);
    }

    /**
     * 获取评论点赞状态
     */
    @RequestMapping("/getCommentFavorite")
    ResponseResult getCommentFavorite(@RequestParam Integer userId, @RequestParam Integer commentId, HttpServletResponse resp) {
        return commentService.findIsFavorite(resp, userId, commentId);
    }

    /**
     * 获取回复我的评论
     */
    @RequestMapping("/getFavoriteCommentByUserId")
    ResponseResult getFavoriteCommentByUserId(@RequestParam Integer userId, HttpServletResponse resp) {
        return commentService.getFavoriteCommentByUserId(resp, userId);
    }

    /**
     * 发布评论
     */
    @PostMapping("/sendComment")
    ResponseResult sendComment(@RequestBody JSONObject jsonParm, HttpServletResponse resp)
    {
        return commentService.saveComment(resp, jsonParm);
    }

    /**
     * 获取回复我的总数
     * @param userId
     * @param resp
     * @return
     */
    @RequestMapping("/getReplyToMECount")
    ResponseResult getReplyToMECount(@RequestParam Integer userId, HttpServletResponse resp) throws Exception
    {
        return commentService.getReplyToMECount(resp, userId);
    }

    /**
     * 获取新增回复我的个数
     * @param userId
     * @param resp
     * @return
     */
    @RequestMapping("/getRecentlyReplyToMECount")
    ResponseResult getRecentlyReplyToMECount(@RequestParam Integer userId, HttpServletResponse resp) throws Exception
    {
        return commentService.getRecentlyReplyToMECount(resp, userId);
    }

}
